package com.example.spring.controller;

import com.example.spring.dao.sys.UserDao;
import com.example.spring.entity.User;
import com.example.spring.utils.UserUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017-4-19.
 */
@RestController
@RequestMapping(value = "/testCtl")
public class ServiceOne {

    @Autowired
    private UserDao userDao;

    Logger logger = LoggerFactory.getLogger(ServiceOne.class);

    @GetMapping("add")
    int add(){
        return 1+4;
    }

    @RequestMapping("/getValue")
    public String getValue(){
//        ServerInfo si = new ServerInfo();
        return null;
    }

    /**
     * 测试通过mysql的 load data infile ,将文件数据直接导入到数据库表中
     * 可以传入一个map作为参数，指定列
     * @param
     * @return
     */
    @RequestMapping("/saveTest")
    public String saveTest(){
        logger.info("22222222222222222222");
        userDao.saveTest();
        logger.info("33333333333333333333");
        //User user = userDao.get("1");
        return "111111111111111111111111111111";
    }

    /**
     * 测试通过mysql的 load data infile ,将文件数据直接导入到数据库表中
     * 可以传入一个map作为参数，指定列
     * @param
     * @return
     */
    @RequestMapping("/getUser")
    public User getUser(){
        logger.info("========  开始getUser()  ========");
        return UserUtils.getUser();
    }

    /**
     * 测试通过mysql的 load data infile ,将文件数据直接导入到数据库表中
     * 可以传入一个map作为参数，指定列
     * @param
     * @return
     */
    @RequestMapping("/testJedis")
    public String TestJedis(){
//        redis.clients.jedis.Jedis;
//        redis.clients.jedis.Pipeline;
        int count = 5000;
        long start = System.currentTimeMillis();
        pipelineTest(count,false);//不使用管道
        long end = System.currentTimeMillis();
        System.out.println("withoutUsePipeline time = "+(end - start));

        long start1 = System.currentTimeMillis();
        pipelineTest(count,true);//使用管道
        long end1 = System.currentTimeMillis();
        System.out.println("withoutUsePipeline time = "+(end1 - start1));


        return "aaaaaaaaaaaaa";
    }

    public void pipelineTest(int count, boolean flag){
        ApplicationContext ac = new ClassPathXmlApplicationContext("");
    }

}
